package com.scau.hwadee.examination.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scau.hwadee.examination.entity.Course;
import com.scau.hwadee.examination.entity.Examfee;
import com.scau.hwadee.examination.entity.Examsession;
import com.scau.hwadee.examination.mapper.ExamfeeMapper;
import com.scau.hwadee.examination.mapper.ExamsessionMapper;
import com.scau.hwadee.examination.mapper.UnifiedexamscheduleMapper;
import com.scau.hwadee.examination.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YHX
 * @date 2019/7/31 18:34
 * description
 */
@Service
public class ExamServiceImpl implements ExamService {

    @Autowired
    private ExamsessionMapper examsessionMapper;

    @Autowired
    private UnifiedexamscheduleMapper unifiedexamscheduleMapper;

    @Autowired
    private ExamfeeMapper examfeeMapper;

    @Override
    public PageInfo<Examsession> getAllExamSessions(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(examsessionMapper.selectAllExamSessions(pageNum, pageSize,null));
    }

    @Override
    public PageInfo<Course> getAllCourseFromExamSessionId(int pageNum, int pageSize, String examSessionId) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(unifiedexamscheduleMapper.selectAllCourseByExamSession(pageNum, pageSize, examSessionId));
    }

    @Override
    public int insertExamFeeList(List<Examfee> examfees) {
        try {
            return examfeeMapper.insertList(examfees);
        }catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int updateExamFee(Examfee examfee) {
        try {
            return examfeeMapper.updateByPrimaryKey(examfee);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
}
